package org.azj.fieldTypeConverter;

import org.ht.config.ColumnInfoXmlReader;

public class DecimalConverter implements ITypeConverter {
	@Override
	public String Convert(Object originValue, String column) throws TypeParseException
	{
		double tmpDecimal = 0.0;
		try {
			if (originValue.toString().isEmpty() == false) {
				tmpDecimal = Double.parseDouble(originValue.toString());
			}
		} catch (Exception e) {
			String tableFullName = column.substring(0, column.lastIndexOf("."));
			String simpleColName = column.substring(tableFullName.length() + 1);
			String msgString = "浮点数类型数据转换失败.正在处理的列是[" + 
					ColumnInfoXmlReader.getXmlReader().getValueByField(tableFullName, simpleColName).DescribeName + "](对应的列名是[" + column + "])";
			if (originValue == null)
			{
				msgString += "输入的实际值是null";
			}
			else 
			{
				msgString += "期待的是浮点数，实际值是[" + originValue.toString() + "]";
			}
			throw new TypeParseException(msgString);
		}
		return String.format("%f", tmpDecimal);
	}
}